
$('form').validate({
    rules: {
        username: {
            required: true,
            rangelength: [5, 10]
        },
        password: {
            required: true,
            rangelength: [5, 10]
        },
        email: {
            required: true,
            email: true
        }
    },
    messages: {
        username: {
            required: '请输入注册账号',
            rangelength: '输入长度必须介于5和10位'
        },
        password: {
            required: '请输入注册密码',
            rangelength: '输入长度必须介于5和10位'
        },
        email: {
            required: '请输入注册邮箱',
            email: '请输入有效的电子邮件地址'
        }
    },
    submitHandler(form) {
        $.ajax({
            url: './severs/register.php',
            type: 'post',
            data: {
                username: $('input[name="username"]').val(),
                password: $('input[name="password"]').val(),
                email: $('input[name="email"]').val()
            },
            dataType: 'json',
            // success: function (msg) {
            //     console.log(msg)
            // }
            success(res) {
                console.log(res);
                if(res.status==1){
                    alert(res.msg)
                    return false;
                }
                if (res.code == 1) {
                    alert(res.msg)
                    location.href="./login.html"
                }
                if (res.code == 0) {
                    alert(res.msg)
                    return false;
                }
            }
        })
    }
})
$('button').click(function(){
    location.href="./login.html"
})